class Person {
    constructor(baseUrl = '') {
        this.baseUrl = baseUrl
    }
    get(url) {
        return new Promise((resolve, reject) => {
            var obj = new XMLHttpRequest()
            obj.open('get', this.baseUrl + url, true)
            obj.send(null)
            obj.onreadystatechange = () => {
                if (obj.readyState == 4 && obj.status == 200) {
                    console.log(JSON.parse(obj.responseText));
                    return resolve(JSON.parse(obj.responseText))
                }
            }
        })
    }
    post(url, params) {
        return new Promise((resolve, reject) => {
            var obj =new XMLHttpRequest()
            obj.open('post', this.baseUrl + url, true)
            obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // 设置请求头
            obj.send(params)
            if (obj.readyState == 4 && obj.status == 200) {
                console.log(JSON.parse(obj.responseText));
                return resolve(JSON.parse(obj.responseText))
            }
        })
    }
}
